package org.dromara.iot.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.iot.domain.bo.IotXfjyryBo;
import org.dromara.iot.domain.vo.IotXfjyryVo;
import org.dromara.iot.service.IIotXfjyryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消防救援人员
 *
 * @author Luo
 * @date 2025-07-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/iot/xfjyry")
public class IotXfjyryController extends BaseController {

    private final IIotXfjyryService iotXfjyryService;

    /**
     * 查询消防救援人员列表
     */
    @SaCheckPermission("iot:xfjyry:list")
    @GetMapping("/list")
    public TableDataInfo<IotXfjyryVo> list(IotXfjyryBo bo, PageQuery pageQuery) {
        return iotXfjyryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出消防救援人员列表
     */
    @SaCheckPermission("iot:xfjyry:export")
    @Log(title = "消防救援人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IotXfjyryBo bo, HttpServletResponse response) {
        List<IotXfjyryVo> list = iotXfjyryService.queryList(bo);
        ExcelUtil.exportExcel(list, "消防救援人员", IotXfjyryVo.class, response);
    }

    /**
     * 获取消防救援人员详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("iot:xfjyry:query")
    @GetMapping("/{id}")
    public R<IotXfjyryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iotXfjyryService.queryById(id));
    }

    /**
     * 新增消防救援人员
     */
    @SaCheckPermission("iot:xfjyry:add")
    @Log(title = "消防救援人员", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IotXfjyryBo bo) {
        return toAjax(iotXfjyryService.insertByBo(bo));
    }

    /**
     * 修改消防救援人员
     */
    @SaCheckPermission("iot:xfjyry:edit")
    @Log(title = "消防救援人员", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotXfjyryBo bo) {
        return toAjax(iotXfjyryService.updateByBo(bo));
    }

    /**
     * 删除消防救援人员
     *
     * @param ids 主键串
     */
    @SaCheckPermission("iot:xfjyry:remove")
    @Log(title = "消防救援人员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iotXfjyryService.deleteWithValidByIds(List.of(ids), true));
    }
}
